<template>
  <!-- 放弃投标 -->
  <el-dialog
    v-model="props.visible"
    width="600px"
    :show-close="false"
    :close-on-click-modal="false"
    :before-close="handleClose"
  >
    <template #header="{ close, titleId, titleClass }">
      <div class="my-header">
        <h4
          :id="titleId"
          :class="titleClass"
        >
          {{t('userCenter.t2')}}
        </h4>
        <img
          src="@/assets/img/icon_guanbi.png"
          @click="close"
          class="close"
        />
      </div>
    </template>

    <div>
      <el-radio-group v-model="refusalReasonList">
        <el-radio
          :label="item.dictValue"
          size="large"
          v-for="item in dictData['refusal_reason']"
        >
          {{ item.dictLabel }}
        </el-radio>
      </el-radio-group>
    </div>

    <template #footer>
      <div class="dialog-footer flexcc">
        <el-button
          type="primary"
          color="#252628"
          @click="confirm"
        >
          {{ t('confirmText') }}
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { onBeforeMount, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import useDict from '@/hooks/useDict'

import { rejectionBidApi as dockOrderRejectionBidApi } from '@/service/dockOrder'
import { rejectionBidApi as procurementRejectionBidApi } from '@/service/procurement'
import { rejectionBidApi as externalAssistanceRejectionBidApi } from '@/service/externalAssistance'

const { dictData, getDictData } = useDict()
const { t, locale } = useI18n()

onBeforeMount(() => {
  init()
})

const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  // 订单id
  orderId: {
    type: [String, Number],
    required: true
  },
  // 1 2 3
  type: {
    type: [String, Number],
    default: 1
  }
})

const emit = defineEmits(['close', 'confirm'])

const handleClose = () => {
  emit('close')
}

// 原因
const refusalReasonList = ref('')

// 确定
const confirm = () => {
  if (!refusalReasonList.value) {
    ElMessage.warning(t('userCenter.w5'))
    return
  }

  const obj = {
    1: dockOrderRejectionBidApi,
    2: procurementRejectionBidApi,
    3: externalAssistanceRejectionBidApi
  }

  obj[props.type]({
    orderId: props.orderId,
    refusalReasonList: [refusalReasonList.value]
  }).then(({ msg }) => {
    ElMessage.success(msg)
    emit('close')
    emit('getList')
  })
}

const init = () => {
  getDictData('refusal_reason')
}
</script>

<style scoped lang="scss"></style>
